package com.reds.backend.service.impl.data;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reds.backend.pojo.Admin;
import com.reds.backend.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.reds.backend.service.data.dataGetService;
import com.reds.backend.mapper.articleMapper;
import com.reds.backend.mapper.adminMapper;

import java.util.Date;

@Service
public class dataGetServiceImpl implements dataGetService{
    @Autowired
    articleMapper articleMapper;
    @Autowired
    adminMapper adminMapper;
    @Override
    public int getArticleSum() {
        return articleMapper.selectCount(null).intValue();
    }

    @Override
    public int getNowDaySum() {
        Date date = new Date();
        date.setTime(date.getTime()-86400000);
        System.out.println(date);
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("time",date);
        return articleMapper.selectCount(queryWrapper).intValue();
    }

    @Override
    public int getAdminSum() {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("role","管理员","超级管理员");
        return adminMapper.selectCount(queryWrapper).intValue();
    }

    @Override
    public int getScenerySum() {
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tag","红色景点");
        return articleMapper.selectCount(queryWrapper).intValue();
    }

    @Override
    public int getStorySum() {
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tag","人物故事");
        return articleMapper.selectCount(queryWrapper).intValue();
    }

    @Override
    public int getActivitySum() {
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tag","精彩活动");
        return articleMapper.selectCount(queryWrapper).intValue();
    }
}
